import request from '@/utils/request';
import { Category } from '@prisma/client';

import { PaginationParams, PaginationResponse } from '@/types/api-common';

export const getCategoryList = (params?: { name?: string }) => {
  return request.post<Category[]>('/api/admin/categories/list', params);
};

export const getCategoryPage = (params: PaginationParams & { name?: string; menuId?: string }) => {
  return request.post<PaginationResponse<Category & { menu: { name: string } }>>(
    '/api/admin/categories/page',
    params
  );
};

export const createCategory = (data: Omit<Category, 'id' | 'createdAt' | 'updatedAt'>) => {
  return request.post<Category>('/api/admin/categories/create', data);
};

export const updateCategory = (data: Category) => {
  return request.post<Category>('/api/admin/categories/update', data);
};

export const deleteCategory = (id: string) => {
  return request.post('/api/admin/categories/delete', { id });
};